#include "LogicHandlerThread.h"
#include "Manager.h"

#include <core/Timer.h>
#include <core/Types.h>

namespace galaxy {
    namespace logic {
        namespace gamestate {

            void LogicHandlerThread::operator()() {
                core::Timer timer;

                m_Manager->m_LogicHandlerThread->m_State = core::Thread::THREAD_STATE_RUNNING;
                while (m_Manager->m_LogicHandlerThread->m_State == core::Thread::THREAD_STATE_RUNNING) {
                    timer.updateTimer ();

                    // limit capturing logic events to 10 times per second.
                    time_duration elapsed = timer.getElapsedDuration ();
                    if (elapsed < milliseconds(100)) {
                        boost::this_thread::sleep(milliseconds(100) - elapsed);
                    }

                }
            }

        } // namespace gamestate
    } // namespace logic
} // namespace galaxy
